package util;

import java.io.*;

public class CodeHelper {
	String path;
	int count = 0;

	public CodeHelper(String path) {
		this.path = path;
	}

	String[] files = { "java", "jsp" };

	public void begin() {
		this.count(this.path);
		System.out.println("------------------------------\n" + "total lines: "
				+ this.count);
	}

	public void count(String path) {
		int num = 0;
		boolean flag = false;
		File file = new File(path);
		try {
			if (file.isFile()) {
				for (String s : this.files) {
					if (path.endsWith("." + s)) {
						flag = true;
					}
				}
				if (flag) {
					BufferedReader in = new BufferedReader(new FileReader(file
							.getAbsoluteFile()));
					try {
						while (in.readLine() != null)
							num++;
					} finally {
						System.out.println(file.getAbsolutePath() + " has "
								+ num + " lines;");
						this.count += num;
						in.close();
					}

				}
			} else {
				for (File item : file.listFiles()) {
					this.count(item.getAbsolutePath());
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		CodeHelper ch = new CodeHelper("E:\\workplace\\jsp_workplace\\xml");
		ch.begin();

	}

}
